package com.cg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @ClassName MyCorsConfiguration
 * @Description TODO
 * @Author CG
 * @Date 2024/1/5 9:14
 **/
@Configuration
public class MyCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource source=new
                UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration=new CorsConfiguration();
        configuration.addAllowedHeader("*");//允许跨域请求头
        configuration.addAllowedMethod("*");//允许跨域请求方式
        configuration.addAllowedOrigin("*");//允许跨域请求来源
        source.registerCorsConfiguration("/**",configuration);
        return new CorsWebFilter(source);
    }
}
